import axios from 'axios';

const API_BASE_URL = '/api';

// 创建axios实例
const api = axios.create({
  baseURL: API_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
  },
});

/**
 * 上传文件并翻译
 * @param formData 包含文件和翻译配置的FormData
 * @returns 翻译结果
 */
export const translateFile = async (formData: FormData) => {
  try {
    const response = await api.post('/translation/translate', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('翻译请求错误:', error);
    throw error;
  }
};